package TreeTraversal;

public class TreeTraversal {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(
                new TreeNode(new TreeNode(4),2,null),
                1,
                new TreeNode(new TreeNode(5),3,new TreeNode(6))
        );
        preOrder(root);
        System.out.println();

        inOrder(root);
        System.out.println();

        postNode(root);
        System.out.println();
    }
    //前序遍历
    static void preOrder(TreeNode node){
        if(node == null){
            return;
        }
        System.out.print(node.val + "\t");
        preOrder(node.left);
        preOrder(node.right);
    }
    static void inOrder(TreeNode node){
        if(node == null){
            return;
        }
        inOrder(node.left);
        System.out.print(node.val + "\t");
        inOrder(node.right);
    }
    static void postNode(TreeNode node){
        if(node == null){
            return;
        }
        postNode(node.left);
        postNode(node.right);
        System.out.print(node.val + "\t");
    }
}
